package com.hk.blog.repository.jpa;

import com.hk.blog.domain.UserInfo;
import com.hk.core.data.jpa.query.specification.Specifications;
import com.hk.core.data.jpa.repository.LongIdJpaRepository;

import java.util.Optional;

public interface UserInfoRepository extends LongIdJpaRepository<UserInfo> {

    Optional<UserInfo> findByUsername(String username);

    Optional<UserInfo> findByMobileNumber(String mobileNumber);

    default boolean existByUsername(String username) {
        return count(Specifications.equals("username", username)) > 0;
    }

    default boolean existByMobileNumber(String mobileNumber) {
        return count(Specifications.equals("mobileNumber", mobileNumber)) > 0;
    }
}
